#include "../Server.hpp"

void ConnectedHandle(const PtrConnection &conn)
{
    DEBUG_LOG("%d号连接已经成功建立!",conn->GetFd());
}

void MessageHandle(const PtrConnection &conn,Buffer *buf)
{
    conn->Send(buf->ReadPosition(),buf->ReadAbleSize());
    buf->OffsetReader(buf->ReadAbleSize());
    conn->Shutdown();
}

void AnyHandle(const PtrConnection &conn)
{
    DEBUG_LOG("%d号连接有事件触发",conn->GetFd());
}

void CloseHandle(const PtrConnection &conn)
{
    DEBUG_LOG("%d号连接断开!",conn->GetFd());
}
int main()
{
    TcpServer server(9090);
    server.EnableInactiveRelease(10);// 10s没有事件触发就销毁连接
    server.SetThreadCount(2);// 3个从属线程
    server.SetConnectedCallback(std::bind(ConnectedHandle,std::placeholders::_1));
    server.SetMessgageCallback(std::bind(MessageHandle,std::placeholders::_1,std::placeholders::_2));
    server.SetClosedCallback(std::bind(CloseHandle,std::placeholders::_1));
    //server.SetAnyEventCallback(std::bind(AnyHandle,std::placeholders::_1));
    server.Start();
    return 0;
}